const usernameEle = document.querySelector('.username')
const btnEle = document.querySelector('.btn')
const passwordEle = document.querySelector('.password')

usernameEle.onblur = ()=>{
    const val = usernameEle.value;
    if(val){
        const reg = /^[a-zA-Z0-9]{1,5}$/;
        if(reg.test(val)){
            $.ajax({
                type:'get',
                url:'/user/checkName',
                data:{
                    name:val
                },
                success:(data)=>{
                    if(!data.status){
                        btnEle.disabled = false
                    }else{
                        alert('重名了！')
                        btnEle.disabled = true
                    }
                }
            })
        }else{
            alert('用户名不规范')
            btnEle.disabled = true
        }
    }else{
        alert('输入用户名啊！')
    }
}

btnEle.onclick = ()=>{
    $.ajax({
        type:'post',
        url:'/user/regist',
        data:{
            username:usernameEle.value,
            password:passwordEle.value
        },
        success:(data)=>{
            console.log(data)
        }
    })

}